package com.nightsoul.hbase.test.coprocessor;

import java.io.IOException;

import org.apache.hadoop.hbase.client.Durability;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.coprocessor.BaseRegionObserver;
import org.apache.hadoop.hbase.coprocessor.ObserverContext;
import org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment;
import org.apache.hadoop.hbase.regionserver.wal.WALEdit;
import org.apache.hadoop.hbase.util.Bytes;

/**
 * Observer类似关系型数据库中的触发器
 * 书上声明Observer使用hbase.coprocessor.master.classes属性配置在hbase-site.xml中，但测试暂时无效
 * 通过改变相应表属性，设置coprocess属性值时有效
 * @author zj
 *
 */
public class DemoObserver extends BaseRegionObserver {
	
	@Override
	public void prePut(ObserverContext<RegionCoprocessorEnvironment> e,
			Put put, WALEdit edit, Durability durability) throws IOException {
		put.add(Bytes.toBytes("info"), Bytes.toBytes("observer_" + System.currentTimeMillis()), Bytes.toBytes(System.currentTimeMillis()));
	}
}
